﻿using Inovout.Memberships.Services;
using Inovout.Web.Mvc;
using Microsoft.Web.WebPages.OAuth;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Inovout.Account.Web.Controllers
{
    [AllowAnonymous]
    public class SystemUserController : BaseController
    {
        public ActionResult Link(string returnUrl)
        {
            ViewBag.ReturnUrl = returnUrl;
            Inovout.Memberships.Models.Membership membership = base.Membership as Memberships.Models.Membership;
            Inovout.Memberships.IMembershipUser membershipUser = Inovout.ComponentRegistry.Resolve<MembershipUserService>().FindByMembership(membership);
            return View(membershipUser);
        }

        [AllowAnonymous]
        public ActionResult ExtensionalLink(string provider)
        {
            string returnUrl = this.Url.Content("~/SystemUser/Link" + this.Request.Url.Query);
            return new AccountAuthenticationResult(provider, Url.Action("ExtensionalSignInCallback", "Account", new { ReturnUrl = returnUrl }));
        }

        [AllowAnonymous]
        [ChildActionOnly]
        public ActionResult ExtensionalLinkList(string returnUrl)
        {
            ViewBag.ReturnUrl = returnUrl;
            return PartialView("_ExtensionalLinkList", OAuthWebSecurity.RegisteredClientData);
        }
    }
}